<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini" onmousedown="xyh.disableRight()" oncontextmenu= "xyh.disableRight()">
<section class="content-header">
    <h1>概算成本清单提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号：
                                    </label>
                                    <label class="control-label">
                                        <input name="code" class="form-control" type="text" maxlength="255" value=""
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称：
                                    </label>
                                    <label class="control-label">
                                        <input name="name" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        需方：
                                    </label>
                                    <label class="control-label">
                                        <input name="demander" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入需方"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        安装地点：
                                    </label>
                                    <label class="control-label">
                                        <input name="address" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入安装地点"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        创建者：
                                    </label>
                                    <label class="control-label">
                                        <input name="userName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入创建者"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        设计类别：
                                    </label>
                                    <label class="control-label">
                                        <select class="form-control" name="projectClassify">
                                            <option value="">请选择</option>
                                            <option value="1">设计</option>
                                            <option value="2">非设计</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        审核状态：
                                    </label>
                                    <label class="control-label">
                                        <select class="form-control" name="appStatus">
                                            <option value="">请选择</option>
                                            <option value="1"selected="selected">未提交</option>
                                            <option value="2">待组级审核</option>
                                            <option value="3">待科级审核</option>
                                            <option value="4">待部级审核</option>
                                            <option value="5">已提交</option>
                                        </select>
                                    </label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success pull-right">
                                    搜索
                                </button>
                            </div>
                        </div>

                    </form>
                </div>
                <div id="toolbar" class="row">
                    <!--                    <button id="btn_getData" class="btn btn-success">获取数据</button>-->
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    /**
     * 表格对象
     **/
    let table;
    /**
     * 审核状态样式
     **/
    let statusClass = ["label-default", "label-danger", "label-warning", "label-success","label-default"];
    /**
     * 审核状态文本
     **/
    let statusText = ["未提交", "被驳回", "待审核", "已审核", "未提交"];
    /**
     * 审核级别样式
     **/
    let approvalLevelMap = new Map();
    approvalLevelMap.set("员工级", "bg-default color-palette");
    approvalLevelMap.set("组长级", "bg-aqua color-palette");
    approvalLevelMap.set("科长级", "bg-purple color-palette");
    approvalLevelMap.set("部长级", "bg-maroon color-palette");
    /**
     * 就绪函数
     **/
    $(function () {
        window.parent.getItemCount();
        $("#btn-search").on('click', function (e) {
            js.table.refresh(table);
        })
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "estimateManage/findSubmitList",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '项目编号', field: 'code',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'name',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '需方', field: 'demander',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '安装地点', field: 'address',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '项目数量', field: 'num',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '设计类别', field: 'projectClassify',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "设计";
                        } else if (value === 2) {
                            return "非设计";
                        }
                    }
                },
                {
                    title: '概算名称', field: 'title',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '创建者', field: "userName",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }, {
                    title: '提交时间', field: "submitTime",
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '审核等级', field: 'approvalLevel',
                    formatter: function (value, row, index) {
                        if (value === null) {
                            value = '员工级';
                        }
                        return '<lable class="badge ' + approvalLevelMap.get(value) + '">' + value + '</lable>';
                    }
                },
                {
                    title: '审核状态', field: 'appStatus',
                    formatter: function (value, row, index) {
                        return '<lable class="badge ' + statusClass[value] + '">' + statusText[value] + '</lable>';
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (row.isSameDept === 1) {
                            if (hasP('rou:submit:commit')) {
                                if (row.userName != null && row.userName === sessionUser.name) {
                                    if(row.isSave===1){
                                        if(row.appStatus === null || row.appStatus === 0 || row.appStatus === 1 || row.appStatus === 4){
                                            elements.push('<button class="btn btn-success btn-xs" onclick="submit(' + row.batId + ')">提交</button>');
                                            elements.push('<button class="btn btn-warning btn-xs" onclick="edit(' + row.batId + ',\'' + row.code + '\')">取消保存并编辑</button>');
                                        }
                                            elements.push('<button class="btn btn-info btn-xs" onclick="view(' + row.batId + ')">查看</button>');


                                    }
                                    if(row.isSave===0){
                                        elements.push('<button class="btn btn-warning btn-xs" onclick="editCostSheet(' + row.batId +')">编辑概算</button>');
                                        elements.push('<button class="btn btn-success btn-xs" onclick="save(' + row.batId + ')">保存概算</button>');
                                        elements.push('<button class="btn btn-danger btn-xs" onclick="removeCostSheet(' + row.batId +')">删除概算</button>');
                                    }
                                }
                            }
                        }
                        return elements.join('');
                    }
                }
            ]
        });


        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("halfAdjEditForm");
            js.reset("halfAdjEditForm");
        });
    });

    /**
     * 跳转到明细页
     **/
    function edit(batId, code) {
        js.confirmPost({
            content: "尊敬的用户，您确定取消保存并编辑此概算清单吗？",
            url: ctx + 'getData/checkIsJump',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                code: code
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    window.open( ctx + 'getData/estimatingCostEditByCancelSave/' + batId + "/" + code);
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        });
    }

    /**
     * 查看成本清单
     **/
    function view(batId) {
        window.open(ctx + 'accountManage/showEstCostSheetByApproval/' + batId+'/seeReject');
    }

    /**
     * 提交
     */
    function submit(id) {
        js.confirmPost({
            content: "尊敬的用户，您确定要提交此表单吗？",
            url: ctx + 'accountManage/estimatingSubmit',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: id
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    location.reload();
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 保存概算成本清单
     * @param batId
     */
    function save(batId){
        js.confirmPost({
            content: "尊敬的用户，您确定要提保存此概算清单吗？",
            url: ctx + 'estimateManage/saveOrder',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: batId
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 编辑概算成本清单
     * @param batId
     */
    function editCostSheet(batId){
        js.post({
            url: ctx + 'estimateManage/checkIsSave',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: batId
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    window.open(ctx+"estimateManage/editEstCostSheet/"+batId);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 删除概算
     * @param baId
     */
    function removeCostSheet(batId){
        js.confirmPost({
            content: "尊敬的用户，您确定要提删除此概算清单吗？",
            url: ctx + 'estimateManage/removeOrder',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: batId
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

</script>
</body>
</html>